package com.tmeone.erpone.controller;

import com.tmeone.erpone.util.FtpUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.UUID;

@Controller
public class UploadController {
    @ResponseBody
    @RequestMapping("/upload")
    public String upload(MultipartFile file) throws IOException {
        String filename = file.getOriginalFilename();
        String filename1 = UUID.randomUUID().toString().replace("-","")+
                filename.substring(filename.lastIndexOf("."));
        FtpUtil.upload("192.168.31.120",21,
                "ftpuser",
                "12345678",
                "/home/ftpuser/images",
                filename1,
                file.getInputStream());
        return filename1;
    }
}
